﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using Locator.Silverlight.Client.Models.ViewModels.Elements;

namespace Locator.Silverlight.Client
{
    public partial class ManageStoresControl : UserControl
    {
        public ManageStoresControl()
        {
            InitializeComponent();
            Locator.Silverlight.Client.Models.ViewModels.ViewModelLocator.ManageStoresStatic.SearchResults.CollectionChanged += SearchResults_CollectionChanged;
        }

        void SearchResults_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            ObservableCollection<UserStoreViewModel> stores = sender as ObservableCollection<UserStoreViewModel>;
            if (stores.Count == 1)
            {
                this.mapResults.SetView(stores[0].Store.Location, 14);
            }
        }

        private void TextBlock_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TextBlock textBlock = e.OriginalSource as TextBlock;
            UserStoreViewModel store = textBlock.DataContext as UserStoreViewModel;
            this.mapResults.SetView(store.Store.Location, 14);
        }
    }
}
